package com.tgy.leetcode;

/**
 * @Author: tgy
 * @Date: 2020-11-26 09:26
 */
public class ListNode {

    public int val;

    public ListNode next;

    public ListNode pre;

    public ListNode getNext() {
        return next;
    }

    public ListNode setNext(ListNode next) {
        this.next = next;
        return next;
    }

    public ListNode(int x) {

        val = x;
    }

    public ListNode() {

        this(0);
    }

    @Override
    public String toString() {
        return "ListNode{" +
                "val=" + val +
                '}';
    }

    public static ListNode general(int[] nums) {

        if (nums == null || nums.length == 0) {

            return null;
        }

        ListNode dummy = new ListNode();
        ListNode tail = dummy;

        for (int num : nums) {

            tail.next = new ListNode(num);
            tail = tail.next;
        }

        return dummy.next;
    }

    public static void printListNode(ListNode node) {

        StringBuilder sb = new StringBuilder();
        while (node != null) {

            sb.append(node.val);
            sb.append(',');
            node = node.next;
        }

        System.out.println(sb.toString());
    }
}
